<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../layui/layui.all.js"  media="all">
</head>
<body>
<form id="defect_table" class="layui-form" method="" action="" style="margin-top: 30px;margin-left: 50px">
    <div style="float: left;">
        <div class="layui-form-item" >
            <label class="layui-form-label"style="text-align: left">任务编号：</label>
            <div class="layui-input-inline">
                <input style="border:none"type="text" id="sovle_task" disabled name="sovle_task"   lay-verify="required|sovle_task" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
            </div>
        </div>
        <label class="layui-form-label" style=" text-align: left">下发人：</label>
        <div class="layui-input-inline">
            <input  style="border:none"type="text" id="user_name" name="user_name" disabled  lay-verify="required|user_name" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label"style="text-align: left">消缺描述：</label>
            <div class="layui-input-inline">
                <input style="border:none"type="text" id="sovle_dec" disabled name="sovle_dec"   lay-verify="required|sovle_dec" autocomplete="off" placeholder="请输入缺陷名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"style=" text-align: left;width: 160px">分配任务：
            <select name="sovle_account" id="sovle_account" lay-filter="xmFilter">
                <option value=""></option>
                <option value=""></option>
                <option value=""></option>
                <option value=""></option>
                <option value=""></option>
            </select>
            </label>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm"type="button" lay-submit="formDemo2" lay-filter="formDemo2"style="margin-left: 55px"> 提交</button>
            </div>
        </div>
    </div>
</form>
<script src="../layui/layui.all.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload','laydate','table','layer'], function() {
        var $ = layui.jquery
            , upload = layui.upload
            , laydate = layui.laydate
            , layedit = layui.layedit
            , form = layui.form
            ,layer=layui.layer
            ,table=layui.table;
        var element = layui.element;
        var test = JSON.parse(sessionStorage.getItem("test"));
        table.render({
            elem: '#test2'
            , url: '/querySolveTask'
            ,title:'缺陷等级'
            ,where:{test:JSON.stringify(test)}
            , cols: [[
                {field: 'sovle_task', title: '任务编号', fixed: 'left',align:'center'}
                , {field: 'solve_name', title: '任务名称', edit: 'text',align:'center'}
                , {field: 'work_order_des', title: '工作单据', edit: 'text',align:'center'}
                , {field: 'user_name', title: '下发人', edit: 'text',align:'center'}
                , {field: 'lssue_time', title: '下发时间', edit: 'text',align:'center',templet : "<div>{{layui.util.toDateString(d.find_time, 'yyyy-MM-dd')}}</div>"}
                , {field: 'state_name', title: '任务状态', edit: 'text',align:'center'}
                , {field: 'sovlesuc_time', title: '任务完成时间', edit: 'text',align:'center',templet : "<div>{{layui.util.toDateString(d.find_time, 'yyyy-MM-dd')}}</div>"}
                , {field: 'yesno_name', title: '任务是否取消', edit: 'text',align:'center'}
                , {field: 'sovle_account', title: '消缺员', edit: 'text',align:'center',style:'display:none'}
                , {field: 'sovle_dec', title: '消缺描述', edit: 'text',align:'center',style:'display:none'}
            ]]
        });
        $.ajax({
            url:"/queryOption",
            data:{},
            dataType:"json",
            type: 'post',
            success: function (data) {
//                   console.log(data);//下面会提到这个data是什么值
                //使用循环遍历，给下拉列表赋值
                $.each(data.data, function (index, value) {
                    $('#sovle_account').append(new Option(value.user_name,value.user_account));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        });
        form.on('submit(formDemo2)', function(data){
            console.log(data.field);
            var sovle_account=data.field.sovle_account;
            var sovle_task=data.field.sovle_task;
            $.ajax({
                url:"/addSovle_account",
                type:"POST",
                dataType: "json",
                data:{sovle_account:sovle_account,sovle_task:sovle_task},
                success:function (res) {
                    layer.open("分配成功！")
                    if (res.code == 200 ){
                        parent.layer.close(parent.layer.index);
                        console.log(res.code);
                    }else if (res.code==500){
                        layer.msg(res.msg,{icon:5});
                    }else if (res.code == 405){
                        layer.msg(res.msg,{icon:5});
                    }
                }
            });
        });
    });
</script>

</body>
</html>